package com.zg.scf.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zg.common.core.dao.scf.RuleItemDao;
import com.zg.common.core.dao.scf.entity.RuleItem;
import com.zg.common.core.service.PageBaseService;
import com.zg.scf.domain.req.rule.RuleItemReq;
import com.zg.scf.service.RuleItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/5/22 10:47
 */

@Slf4j
@Service
public class RuleItemServiceImpl extends PageBaseService<RuleItem, RuleItemDao> implements RuleItemService {

//    @Autowired
//    @Qualifier("confCompanyItemDao")
//    @Override
//    protected void setDao(IDao<ConfCompanyItem> dao) {
//        this.dao = dao;
//    }

    public  LambdaQueryWrapper<RuleItem> buildQueryWrapper(RuleItem msgInfo){
        LambdaQueryWrapper<RuleItem> qw = new LambdaQueryWrapper<>();
        return qw;
    }


    public void batchAdd(List<RuleItemReq> list){

        List<Long> configIdList = list.stream().map(t->t.getRuleId()).collect(Collectors.toList());
        LambdaQueryWrapper<RuleItem> qw = new LambdaQueryWrapper<>();
        qw.in(RuleItem::getRuleId,configIdList);
        baseDao.remove(qw);

        list.forEach(t->{
            RuleItem item = new RuleItem();
            BeanUtils.copyProperties(t,item);
            baseDao.save(item);
        });

    }

    public List<RuleItem> listByRuleId(String configId){

        LambdaQueryWrapper<RuleItem> qw = new LambdaQueryWrapper<>();
        qw.eq(RuleItem::getRuleId,configId);
        return baseDao.list(qw);

    }

}
